﻿using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;


namespace user.admin.cyt369.com.services.Services
{
    public class TermsService : admin.cyt369.com.services.ORM.BaseService<TermsService>
    {
        public TermsService() { }

        #region TermsType
        public IQueryable<cyt369.com.services.Models.TermsType> GetTermsTypes(int page, int rows, ref int total, string name = null)
        {
            var items = base.Get<cyt369.com.services.Models.TermsType>();
            if (!string.IsNullOrEmpty(name))
            {
                items = items.Where(c => c.Name.Contains(name));
            }

            return this.Pagination(page, rows, ref total, items, c => c.Id);
        }

        public IQueryable<cyt369.com.services.Models.TermsType> GetAllTermsTypes()
        {
            var items = base.Get<cyt369.com.services.Models.TermsType>();

            return items;
        }

        public cyt369.com.services.Models.TermsType GetTermsTypeByID(int id)
        {
            return base.GetOne<cyt369.com.services.Models.TermsType>(c=>c.Id == id);
        }

        public bool SaveTermsType(cyt369.com.services.Models.TermsType userType)
        {
            return this.Save<cyt369.com.services.Models.TermsType>(userType, c => c.Id == userType.Id);
        }

        public bool DeleteTermsType(int id)
        {
            return base.Delete<cyt369.com.services.Models.TermsType>(c => c.Id == id);
        }
        #endregion

        #region Terms
        public IQueryable<cyt369.com.services.Models.Terms> GetTerms(int page, int rows, ref int total, string name = null)
        {
            var items = base.Get<cyt369.com.services.Models.Terms>();
            if (!string.IsNullOrEmpty(name))
            {
                items = items.Where(c => c.Name.Contains(name));
            }

            return this.Pagination(page, rows, ref total, items, c => c.Id);
        }

        public cyt369.com.services.Models.Terms GetTermsByID(long id)
        {
            return base.GetOne<cyt369.com.services.Models.Terms>(c => c.Id == id);
        }

        public bool SaveTerms(cyt369.com.services.Models.Terms terms)
        {
            return this.Save<cyt369.com.services.Models.Terms>(terms, c => c.Id == terms.Id);
        }

        public bool DeleteTerms(long id)
        {
            return base.Delete<cyt369.com.services.Models.Terms>(c => c.Id == id);
        }
        #endregion

    }
}
